const axios = require('axios');

// 测试Google登录
async function testGoogleLogin() {
  try {
    // 替换为您的实际Access Token
    const accessToken = 'ya29.A0AS3H6NxHLey-eJ4EU5dV2VqJeEdR0vfgMQqIAinGGgD2CQJzSe7A_nurjfMVFD2ZkCmbTlcR9Ngiit5B1vrpF_xz4TG9l_PSV3kRri7OUH-kOmwy5oJx3J5iHEl67qcRWDAlAm5KJpxp0DxC5HxQvKg298MPs7VU15E235RV1QyPcGtbSq4UVNV9MxsTHMs2q7Z5G9K4781IixfddwYBJsM6Y1JYAwOEOHF54javwf8eWlypcxhWDjqH3lc627ejNaiVngdquFIraCgYKAX8SARUSFQHGX2MipjSptcn64x4Ni2LmBekckg0275';
    
    console.log('🔍 测试Google Access Token...');
    console.log('Token类型:', accessToken.startsWith('ya29.') ? 'Access Token' : 'ID Token');
    
    // 直接调用Google API测试
    const response = await axios.get('https://www.googleapis.com/oauth2/v2/userinfo', {
      headers: {
        'Authorization': `Bearer ${accessToken}`,
      },
    });
    
    console.log('✅ Google API调用成功!');
    console.log('用户信息:', {
      id: response.data.id,
      email: response.data.email,
      name: response.data.name,
      picture: response.data.picture,
    });
    
    // 测试后端API
    console.log('\n🔍 测试后端Google登录API...');
    const backendResponse = await axios.post('http://localhost:3000/api/auth/google-login', {
      idToken: accessToken
    });
    
    console.log('✅ 后端API调用成功!');
    console.log('响应:', backendResponse.data);
    
  } catch (error) {
    console.error('❌ 测试失败:', error.message);
    if (error.response) {
      console.error('响应状态:', error.response.status);
      console.error('响应数据:', error.response.data);
    }
  }
}

// 运行测试
testGoogleLogin(); 